/**
 *功能描述 卡片 
 */
define(function (require, exports, module) {
	var aw = require("ajaxwrapper");
	var Form = require("form");
	var Dialog = require("dialog");
	var store =require("store");
	var activeUser = store.get("user");	
	var enmu = require("enums");
    var instance = {
        initComponent: function (params,widget) {
        	var form = new Form({
        		show:false,
        		parentNode:".J-form",
        		saveaction:function(){
        			var data = form.getData();
					aw.saveOrUpdate("api/allianceorg/saveorg",data,function(data){
						widget.get("grid").refresh();
						widget.show([".J-grid"]).hide([".J-form"]);
						widget.get("subnav").hide(["return"]).show(["add"]);
					});
        			
        		},
        			 cancelaction : function(){
           			     widget.show([".J-grid"]).hide([".J-form"]);
    					 widget.get("subnav").hide(["return"]).show(["add"]);
    					 widget.get("grid").refresh();
        			 },
        			 model:{
        				 id:"allianceorg",
        				 layout:"2_1",
        				 items:[{
        					 name:"pkAllianceOrg",
     						 type:"hidden"
        				 },{
        					 name:"organization",
     					     type:"hidden",
     					     defaultValue:activeUser.organization.pkOrganization
        				 },{
        					 name:"name",
     						 id:"name",
     						 label:"名称",
     						 validate:["required"],
	     					 exValidate: function(value){
	   							  var reglen = new RegExp(/^[\u4E00-\u9FA5A-Za-z0-9]+$/);
	   							  if(reglen.test(value)==true && value.length<20){
	   								   return true;
	   							}else{
	   								  return "只能输入数字、字母和汉字"
   							}
   						 }
        				 },{
        					 name:"orgOwnership",
        					 label:"单位性质",
        					 type:"select",
        					 validate:["required"],
        					 options:enmu["com.eling.elcms.travel.model.AllianceOrg.OrgOwnership"]
        				 },{
        					 name:"address",
     						 type:"place",
     						 label:"省/市/区（县）",
     						 validate:["required"]
        				 },{
        					 name:"street",
     						 label:"详细地址" ,
     						 validate:["required"],
     						 exValidate: function(value){
     							  var reg = /^[\u4E00-\u9FA5A-Za-z0-9\-\/\\\.\(\)\~\<\>\[\]\{\}\（\）\，\,]{1,50}$/;
     	                          if (!reg.test(value)) {
     	                                return "只能输入数字、字符、字母和汉字且不能超过50个字!";
     	                            } else {
     	                                return true;
     	                            }
     						 }
        				 },{
        					 name:"principal",
        					 id:"principal",
     						 label:"负责人",
     						 validate:["required"],
     						 exValidate: function(value){
     							 var reglen = new RegExp(/^[\u4E00-\u9FA5A-Za-z]+$/);
     							 if(reglen.test(value)==true && value.length<15){
     								 return true;
     							 }else{
     								 return "只能输入字母和汉字"
     							 }
     						 }
     						 
        				 },{
        					 name:"phone",
     						 label:"联系电话",
     						 validate:["required"],
     						/* exValidate: function(value){
     							var reglen = new RegExp(/^[\d]/g);
      							//if(value.length>11 && value.match(/^[\d]/g)==false){
     							 if(reglen.test(value)==true && value.length<12){
      								return true;
      							}else{
      								return "联系电话只能输入数字且不能超过11个字";
      							}
      						}*/
        				 },{
        					 name:"description",
     						 type:"textarea",
     						 label:"备注",
     						 "break":true,	
     						 exValidate: function(value){
     							 var reglen = new RegExp(/^[\u4E00-\u9FA5A-Za-z0-9]+$/);
     							 if(value.length == ""){
     								 return true;
     							 }else if(value.length<51 && reglen.test(value)==true){
     								 return true;
     							 }else{
     								return "只能输入数字、字母和汉字且不能超过50个字"
     							 }
     						 }
//    							 var reglen = new RegExp(/^[\u4E00-\u9FA5A-Za-z0-9]+$/);
//    							 if(value.length = " " || value.length<51){
//    								 if(reglen.test(value)==true){
//    									 return true;
//    								 }else{
//    								 return "只能输入数字、字母和汉字"
//    							 }
//    							 }
//    						 }
        				 },{
        					 name:"version",
     						 type:"hidden",
     						 defaultValue:"0"
        				 }]
        			 }
        	});
        	widget.set("form", form);
        }
    };
    module.exports = instance;
});
